# coding:utf-8

"""
tf_demo03_variable
Created on 2016/12/9 14:16
@author: GuoYufu
@group : OceanHorn
@contact: OceanHorn@163.com
"""

import tensorflow as tf

state = tf.Variable(initial_value=2, name="counter")
print state.name  # counter:0 name:value

constant_one = tf.constant(value=1)
print constant_one.name  # Const:0  default_name: value

new_value = tf.add(state, constant_one)
update = tf.assign(ref=state, value=new_value)

initialize = tf.global_variables_initializer()   # 用于在run时激活变量，定义变量时必须有本部

with tf.Session() as session:
    session.run(fetches=initialize)
    # print state
    # print session.run(state)
    # print state.name
    for _ in range(3):
        session.run(fetches=update)
        print session.run(state)




